Ext.define("TT.tool",{
	parent: null,
	constructor: function () {
		var arg = arguments[0];
		this.parent = arg.parent;
		this.createToolPanel(arg.id, arg.title); 
    },
	 createToolPanel: function(id, title){
		var that = this;
		var panel = tabs[id];
		if(!panel){	
			panel = Ext.create('Ext.panel.Panel', {
			    title:title,
			    layout:"border",
			    closable:true,
			    onRemoved: function(destroying) {
			    	delete tabs[id];
			    },
			    items:[
			    	{
			    		region:"north",
			    		height:60
			    	},
			    	{
			    		title:"工具与技术说明", 
			    		region:"center"
			    	},
			    	{
			    		title:"相关过程", 
			    		region:"east",
			    		width:220,
			    		collapsible: true,
			    		autoScroll:true,
			    		layout: {
			    	        type: 'vbox',
			    	        align: 'middle'
			    	    }
			    	}/*,
			    	{
			    		title:"工具介绍", 
			    		region:"south", 
			    		height:0,
			    		autoScroll:true
			    	}*/
			    	
			    ]
			});
			this.parent.add(panel);
			
			tabs[id] = panel;//{10001, p}
			var that = this;
			Ext.Ajax.request({
			    url: "tool/"+(id-200)+".json",
			    params: {
			        id: 2
			    },
			    success: function(response){
			        var text = response.responseText;
			        var tool = Ext.JSON.decode(text).tool;
			        var item = panel.items.items;
			        var north = item[0];
			        //var west = item[1];
			        var center = item[1];
			        var east = item[2];
			        //var south = item[3];
			        
			        var html ="<div style='padding:5px;text-align:center'><h2 class=\"x-panel-header\">工具与技术: "+tool.name+"</h2></div>";
			        north.body.update(html);
		
			       
			        center.add(that.createToolContent(id-200));
			        //center.render();
			        
			        //html = "<div style='padding:10px;'>";
			        for(var i=0;i<tool.processes.length;i++){
			        	//html += "<li><a href=\"javascript:createProcessPanel("+(Number(tool.processes[i].id)+10000)+", '"+tool.processes[i].displayName+"')\">"+tool.processes[i].displayName+"</a></li>";
			        	east.add({
			                xtype: 'button',
			                forId: 'myFieldId',
			                idx: i,
			                text: tool.processes[i].displayName,
			                margin: '3',
			                listeners: {
			                	click:function(){
			                		Ext.create("TT.process",{id:Number(tool.processes[this.idx].id)+10000, title:tool.processes[this.idx].displayName, parent:that.parent});
			                	}
				            }
			            });
			        }
			       // html += "</div>";
			       //east.body.update(html);
			        
			        /*
			        html = "<div style='padding:10px;'><h2 class=\"x-panel-header\"></h2>";
			        html += "</div>";
			        south.body.update(html);
			        */
			    }
			});
		}
		this.parent.setActiveTab(panel);
	
	},
	 createToolContent:function(id){
		
	}
/*
function createToolGrid(){
	var store = Ext.create('Ext.data.Store', {
	    storeId:'simpsonsStore',
	    fields:['name', 'email', 'phone', 'date'],//model
	    data:{
	    	'items':[
		        { 'name': 'Lisa',  "email":"lisa@simpsons.com",  "phone":"555-111-1224", "date":"555-111-1224"  },
		        { 'name': 'Bart',  "email":"bart@simpsons.com",  "phone":"555-222-1234", "date":"555-111-1224"  },
		        { 'name': 'Homer', "email":"homer@simpsons.com",  "phone":"555-222-1244",  "date":"555-111-1224"  },
		        { 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254",  "date":"555-111-1224"  },
		        { 'name': 'Marge2', "email":"marge@simpsons.com2", "phone":"555-222-12542",  "date":"555-111-12242"  }
	        ]
	    },
	    proxy: {
	        type: 'memory',
	        reader: {
	            type: 'json',
	            rootProperty: 'items'
	        }
	    }
	});
	store.load({
	    params: {
	        // specify params for the first page load if using paging
	        start: 1,
	        limit: 2
	    }
	});
	
	var gridPanel = Ext.create('Ext.grid.Panel', {
	    store: Ext.data.StoreManager.lookup('simpsonsStore'),
	    columns: [
	        { 	
	        	text: 'Name',  
	        	dataIndex: 'name', 
	        	editor: {
					xtype: 'textfield',
					allowBlank: false
				}
	        },
	        { text: 'Email', dataIndex: 'email', flex: 1,editor: 'textfield' },
	        { text: 'Phone', dataIndex: 'phone',editor: 'textfield' },
	        { text: 'Date', dataIndex: 'date',editor: 'datefield' }
	    ],
	    selType: 'rowmodel',
	    plugins: [
	        Ext.create('Ext.grid.plugin.RowEditing', {
	            clicksToEdit: 1
	        })
	    ],
	    dockedItems: [{
	        xtype: 'pagingtoolbar',
	        store: store,   // same store GridPanel is using
	        dock: 'bottom',
	        displayInfo: true
	    }]

//	    selType: 'cellmodel',
//	    plugins: [
//	        Ext.create('Ext.grid.plugin.CellEditing', {
//	            clicksToEdit: 1
//	        })
//	    ]
	});
	return gridPanel;
}
*/
});